package cn.itcast.web.servlet;

import cn.itcast.service.UserService;
import cn.itcast.service.impl.UserServiceImpl;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/activeUserServlet")
public class activeUserServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       String code= request.getParameter("code");
       if (code!=null){

           UserService service=new UserServiceImpl();
           boolean flg=service.active(code);

           if (flg){
               request.setAttribute("sert","激活成功，请登录");
               request.getRequestDispatcher("/login.jsp").forward(request,response);
           }else {
               request.setAttribute("sert","激活失败，请联系管理员");
               request.getRequestDispatcher("/register.jsp").forward(request,response);
           }

       }
    }
}
